Session 3 : Exercises

Exercise 1

Create Plots for the flow functions and the price of anarchy function computed in Exercise 2.3.
Given the cost functions

c1[x_]:=x+1;
c2[x_]:=2x

the plots should look something like this (for 0≤r≤2):

Solution

(* Plot the Equilibrium flow functions *)
Plot[eqflows,{r,0,2},
 PlotLabel->"Wardrop Equilibrium Flow Functions",
PlotLegends->"Expressions",
PlotLabels->{"x1", "x2"}]

(* Plot the optimal flow functions *)
Plot[optflows,{r,0,2},
 PlotLabel->"Wardrop Equilibrium Flow Functions",
PlotLegends->"Expressions",
PlotLabels->{"xOpt1", "xOpt2"}]

Plot[poa,{r,0,2}, PlotLabel->"Price of Anarchy", PlotLegends->"Expressions"]

Exercise 2

Execute the code of Exercise 2.3 with the cost functions

c1[x_]:=a1*x;
c2[x_]:=1;

Then create a dynamic plot of the price of anarchy function for 0≤r≤2 (with Manipulate[ ]) that enables you to manipulate the parameter 0<(Subscript[a, 1])<10.
Hint: You might need to use a replacement rule like a1 /. -> x  where x is the variable of the Manipulate function, to really plug in the manipulated variable into the expression that is plotted.

Solution

(* This should be the price of anarchy function generated by Ex. 2.3 *)
poa=Piecewise[{{4/(-1+4*a1*r),a1*r==1},{4*a1^2*r^2,2*a1*r==1},{1,2*a1*r≤1},{(4*a1^2*r^2)/(-1+4*a1*r),1/2≤a1*r≤1},{(2*a1^2*r^2)/(-1+2*a1*r+2*a1^2*r^2),a1*r≤1},{(4*a1*r)/(-1+4*a1*r),a1*r≥1},{(4*(-1+a1*r+a1^2*r^2))/(-1+4*a1*r),2*a1*r≥1}},(2*(-1+a1*r+a1^2*r^2))/(-1+2*a1*r+2*a1^2*r^2)];
(* The solution *)
Manipulate[
Plot[poa/.a1->a,{r,0,2}, PlotRange->{1,4/3}],
{a,0,10}
]